import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { LoginService } from '../../shared/service/login.service';

@Component({
  selector: 'app-user',
  templateUrl: './user.component.html',
  styleUrls: ['./user.component.scss']
})
export class UserComponent implements OnInit {

  user: any;

  constructor(
    private loginService: LoginService,
    private router: Router
  ) { }

  ngOnInit() {
    // 检查是否有用户登录
    this.ifLogin();
  }

  /*****
  *  检查是否有用户登录
  *  @param  :  (参数)
  *  @return :  (返回值说明)
  *****/
  ifLogin() {
    this.user = this.loginService.user;
    if (!this.user) {
      this.router.navigateByUrl('/login');
    }
  }

}
